package com.tycoin.app.controller;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
import java.util.Random;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.json.JSONException;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.MultiFormatWriter;
import com.google.zxing.common.BitMatrix;
import com.tycoin.SpringContextHolder;
import com.tycoin.account.slaveentity.TycoinAccount;
import com.tycoin.account.slaveentity.TycoinUserWallet;
import com.tycoin.account.slaveservice.TycoinAccountService;
import com.tycoin.account.slaveservice.TycoinUserWalletService;
import com.tycoin.app.response.BaseRespose;
import com.tycoin.common.bean.PageInfo;
import com.tycoin.news.slaveentity.TycoinNews;
import com.tycoin.news.slaveservice.TycoinNewsService;
import com.tycoin.setting.slaveentity.TycoinSysArea;
import com.tycoin.setting.slaveservice.TycoinSysAreaService;
import com.tycoin.trate.slaveentity.TycoinTradeOrder;
import com.tycoin.trate.slaveservice.TycoinTradeOrderService;
import com.tycoin.user.slaveentity.TycoinUser;
import com.tycoin.user.slaveentity.TycoinUserBank;
import com.tycoin.user.slaveentity.TycoinUserLoginLog;
import com.tycoin.user.slaveentity.TycoinUserRealnamePic;
import com.tycoin.user.slaveservice.TycoinUserBankService;
import com.tycoin.user.slaveservice.TycoinUserLoginLogService;
import com.tycoin.user.slaveservice.TycoinUserRealnamePicService;
import com.tycoin.user.slaveservice.TycoinUserService;
import com.tycoin.utils.VerifyCodeUtils;
import com.util.HttpClientUtils;
import com.util.MatrixToImageWriter;
import com.util.RandomUtils;
import com.util.StringUtil;
import com.youtu.Verification;
 

@Controller
@RequestMapping(value = { "" })
public class HomeController extends AbstractController{

	private static final Logger logger = LoggerFactory.getLogger(HomeController.class);
	@Autowired
	BaseRespose baseRespose;

	@Autowired
	private TycoinUserService tycoinUserService;
	
	@Autowired
	private TycoinAccountService tycoinAccountService;
	
	@Autowired
	private TycoinUserBankService tycoinUserBankService;
	
	
	@Autowired
	private TycoinUserLoginLogService tycoinUserLoginLogService;
	@Autowired
	private TycoinUserRealnamePicService tycoinUserRealnamePicService;
	
	
	@Autowired
	private TycoinSysAreaService tycoinSysAreaService;
	
	
	@Autowired
	private TycoinTradeOrderService tycoinTradeOrderService;
	
	@Autowired
	private TycoinUserWalletService tycoinUserWalletService;
	
	@Autowired
	private TycoinNewsService tycoinNewsService;
	
 
	//index页面
 	@RequestMapping({ "" })
	public String index(HttpServletRequest request, HttpServletResponse response)  {
		TycoinUser tycoinUser=setUserInfoPageResultUser(request,response);
		if(tycoinUser!=null){
	 		TycoinAccount tycoinAccount =tycoinAccountService.findOneByuserId(String.valueOf(tycoinUser.getId()));
	 		request.setAttribute("tycoinAccount",tycoinAccount);
 		}
 		
		//咨询分页
		PageInfo pageInfo =new PageInfo();
  		pageInfo.setSize(6);
		pageInfo.setPage(0);
		List<TycoinNews> TycoinNewsZXList=tycoinNewsService.queryByPage(1, pageInfo);
	    for (int i = 0,j=TycoinNewsZXList.size(); i < j; i++) {
		  String content=TycoinNewsZXList.get(i).getContent();
		  if(content.length()>100){
			  TycoinNewsZXList.get(i).setContent(content.substring(0,100));
		  }
	    }
		request.setAttribute("TycoinNewsZXList",TycoinNewsZXList);
 		
		
		
		//媒体分页
		PageInfo pageInfos =new PageInfo();
  		pageInfo.setSize(10);
		pageInfo.setPage(0);
		List<TycoinNews> TycoinNewsLists=tycoinNewsService.queryByPage(2, pageInfos);
		List<TycoinNews> TycoinNewsListM1=new ArrayList<TycoinNews>();
		List<TycoinNews> TycoinNewsListM2=new ArrayList<TycoinNews>();
	      for (int i = 0,j=TycoinNewsLists.size(); i < j; i++) {
  			       if(i<5){
			    	   TycoinNewsListM1.add(TycoinNewsLists.get(i));
			       }else{
			    	   TycoinNewsListM2.add(TycoinNewsLists.get(i));
			       }
		}
		request.setAttribute("TycoinNewsListM1",TycoinNewsListM1);
		request.setAttribute("TycoinNewsListM2",TycoinNewsListM2);
		
   		return "/index";
	}

	@RequestMapping ( "/{variable}" )
	public String  test(@PathVariable String variable,HttpServletRequest request, HttpServletResponse response)  {
		TycoinUser tycoinUser=setUserInfoPageResultUser(request,response);
		return variable;
	}
	
	
	//index页面
	@RequestMapping({ "/index" })
	public String index2(HttpServletRequest request, HttpServletResponse response)  {
		TycoinUser tycoinUser=setUserInfoPageResultUser(request,response);
		if(tycoinUser!=null){
	 		TycoinAccount tycoinAccount =tycoinAccountService.findOneByuserId(String.valueOf(tycoinUser.getId()));
	 		request.setAttribute("tycoinAccount",tycoinAccount);
 		}
		//咨询分页
		PageInfo pageInfo =new PageInfo();
  		pageInfo.setSize(6);
		pageInfo.setPage(0);
		List<TycoinNews> TycoinNewsZXList=tycoinNewsService.queryByPage(1, pageInfo);
	    for (int i = 0,j=TycoinNewsZXList.size(); i < j; i++) {
		  String content=TycoinNewsZXList.get(i).getContent();
		  if(content.length()>100){
			  TycoinNewsZXList.get(i).setContent(content.substring(0,100));
		  }
	    }
		request.setAttribute("TycoinNewsZXList",TycoinNewsZXList);
		
		
		
		//媒体分页
		PageInfo pageInfos =new PageInfo();
  		pageInfo.setSize(10);
		pageInfo.setPage(0);
		List<TycoinNews> TycoinNewsLists=tycoinNewsService.queryByPage(2, pageInfos);
		List<TycoinNews> TycoinNewsListM1=new ArrayList<TycoinNews>();
		List<TycoinNews> TycoinNewsListM2=new ArrayList<TycoinNews>();
	      for (int i = 0,j=TycoinNewsLists.size(); i < j; i++) {
 			       if(i<5){
			    	   TycoinNewsListM1.add(TycoinNewsLists.get(i));
			       }else{
			    	   TycoinNewsListM2.add(TycoinNewsLists.get(i));
			       }
		}
	      
	     request.setAttribute("TycoinNewsListM1",TycoinNewsListM1);
		request.setAttribute("TycoinNewsListM2",TycoinNewsListM2);
			

		
		return "/index";
				
	}
	
	//登录页面
	@RequestMapping({ "/login" })
	public String login(HttpServletRequest request, HttpServletResponse response)  {
 		setUserInfoPage(request,response);
 		return "/login";
				
	}
	
	//修改密码
	@RequestMapping({ "setPassword" })
	public String setPassword(HttpServletRequest request, HttpServletResponse response)  {
 		setUserInfoPage(request,response);
 		return "/setPassword";
				
	}
	
	//注册页面
	@RequestMapping({ "/register" })
	public String register(HttpServletRequest request, HttpServletResponse response)  {
 		setUserInfoPage(request,response);
 		return "/register";
 	}


	
	//交易页面
	@RequestMapping({ "/trade" })
	public String trade(HttpServletRequest request, HttpServletResponse response)  {
		TycoinUser tycoinUser=setUserInfoPageResultUser(request,response);
		if(tycoinUser!=null){
	 		TycoinAccount tycoinAccount =tycoinAccountService.findOneByuserId(String.valueOf(tycoinUser.getId()));
	 		request.setAttribute("tycoinAccount",tycoinAccount);
 		}else{
 	 		return "/login";
 		}
 		return "/trade";
 	}
	
	//交易btc
	@RequestMapping({ "/trade_btc" })
	public String tradeBtc(HttpServletRequest request, HttpServletResponse response)  {
		TycoinUser tycoinUser=setUserInfoPageResultUser(request,response);
		if(tycoinUser!=null){
	 		TycoinAccount tycoinAccount =tycoinAccountService.findOneByuserId(String.valueOf(tycoinUser.getId()));
	 		request.setAttribute("tycoinAccount",tycoinAccount);
 		} 
		PageInfo pageInfo =new PageInfo();
  		pageInfo.setSize(4);
		pageInfo.setPage(0);
		Page<TycoinTradeOrder> tycoinTradeOrderPage=tycoinTradeOrderService.getTycoinTradeOrderForSize("BTC", tycoinUser.getId()+"", pageInfo.getPageRequest());
		request.setAttribute("tycoinTradeOrderList", tycoinTradeOrderPage.getContent());
  		return "/trade_btc";
 	}
	
	//交易ltc
	@RequestMapping({ "/trade_ltc" })
	public String tradeLtc(HttpServletRequest request, HttpServletResponse response)  {
		TycoinUser tycoinUser=setUserInfoPageResultUser(request,response);
		if(tycoinUser!=null){
	 		TycoinAccount tycoinAccount =tycoinAccountService.findOneByuserId(String.valueOf(tycoinUser.getId()));
	 		request.setAttribute("tycoinAccount",tycoinAccount);
 		} 
		PageInfo pageInfo =new PageInfo();
  		pageInfo.setSize(4);
		pageInfo.setPage(0);
		Page<TycoinTradeOrder> tycoinTradeOrderPage=tycoinTradeOrderService.getTycoinTradeOrderForSize("LTC", tycoinUser.getId()+"", pageInfo.getPageRequest());
		request.setAttribute("tycoinTradeOrderList", tycoinTradeOrderPage.getContent());
 		return "/trade_ltc";
 	}
	
	
	//交易ltc
	@RequestMapping({ "/trade_eth" })
	public String tradeEth(HttpServletRequest request, HttpServletResponse response)  {
		TycoinUser tycoinUser=setUserInfoPageResultUser(request,response);
		if(tycoinUser!=null){
	 		TycoinAccount tycoinAccount =tycoinAccountService.findOneByuserId(String.valueOf(tycoinUser.getId()));
	 		request.setAttribute("tycoinAccount",tycoinAccount);
 		} 
		PageInfo pageInfo =new PageInfo();
  		pageInfo.setSize(4);
		pageInfo.setPage(0);
		Page<TycoinTradeOrder> tycoinTradeOrderPage=tycoinTradeOrderService.getTycoinTradeOrderForSize("ETH", tycoinUser.getId()+"", pageInfo.getPageRequest());
		request.setAttribute("tycoinTradeOrderList", tycoinTradeOrderPage.getContent());
 		
 		return "/trade_eth";
 	}
	
	//交易ltc
	@RequestMapping({ "/trade_etc" })
	public String tradeEtc(HttpServletRequest request, HttpServletResponse response)  {
		TycoinUser tycoinUser=setUserInfoPageResultUser(request,response);
		if(tycoinUser!=null){
	 		TycoinAccount tycoinAccount =tycoinAccountService.findOneByuserId(String.valueOf(tycoinUser.getId()));
	 		request.setAttribute("tycoinAccount",tycoinAccount);
 		} 
		PageInfo pageInfo =new PageInfo();
  		pageInfo.setSize(4);
		pageInfo.setPage(0);
		Page<TycoinTradeOrder> tycoinTradeOrderPage=tycoinTradeOrderService.getTycoinTradeOrderForSize("ETC", tycoinUser.getId()+"", pageInfo.getPageRequest());
		request.setAttribute("tycoinTradeOrderList", tycoinTradeOrderPage.getContent());
 		
 		return "/trade_etc";
 	}
	
	
	
	//交易list页面
	@RequestMapping({ "/tradelist" })
	public String tradelist(HttpServletRequest request, HttpServletResponse response)  {
 		setUserInfoPage(request,response);
		return "/tradelist";
 	}
	//交易列表页面
	@RequestMapping({ "/trade_entrust_list" })
	public String tradeEntrustList(HttpServletRequest request, HttpServletResponse response)  {
 		setUserInfoPage(request,response);
		return "/trade_entrust_list";
 	}
		
	//委托列表页面
	@RequestMapping({ "/trade_transaction_list" })
	public String tradeTransactionList(HttpServletRequest request, HttpServletResponse response)  {
 		setUserInfoPage(request,response);
		return "/trade_transaction_list";
 	}
	
	
	//更换手机
	@RequestMapping({ "/userCenter_bindMobile" })
	public String userCenterBindMobile(HttpServletRequest request, HttpServletResponse response)  {
 		setUserInfoPage(request,response);
		return "/userCenter_bindMobile";
 	}
	
	//绑定邮箱
	@RequestMapping({ "/userCenter_bindEmail" })
	public String userCenterBindEmail(HttpServletRequest request, HttpServletResponse response)  {
 		setUserInfoPage(request,response);
		return "/userCenter_bindEmail";
 	}
	
	//更改登录密码
	@RequestMapping({ "/userCenter_setLoginPwd" })
	public String userCenterSetLoginPwd(HttpServletRequest request, HttpServletResponse response)  {
  		setUserInfoPage(request,response);
 
		return "/userCenter_setLoginPwd";
 	}
	
	//更改支付密码
	@RequestMapping({ "/userCenter_setPayPwd" })
	public String userCenterSetPayPwd(HttpServletRequest request, HttpServletResponse response)  {
		setUserInfoPage(request,response);
		return "/userCenter_setPayPwd";
 	}
	//我的奖品
	@RequestMapping({ "/userCenter_myGift" })
	public String userCenterMyGift(HttpServletRequest request, HttpServletResponse response)  {
		setUserInfoPage(request,response);
		return "/userCenter_myGift";
 	}
	//我的收货地址
	@RequestMapping({ "/userCenter_myAddress" })
	public String userCenterMyAddress(HttpServletRequest request, HttpServletResponse response)  {
		setUserInfoPage(request,response);
		return "/userCenter_myAddress";
 	}
	//我的登录历史
	@RequestMapping({ "/userCenter_loginHistory" })
	public String userCenterLoginHistory(HttpServletRequest request, HttpServletResponse response)  {
		setUserInfoPage(request,response);
		return "/userCenter_loginHistory";
	 }
	//我的积分
	@RequestMapping({ "/userCenter_myIntegral" })
	public String userCenterMyIntegral(HttpServletRequest request, HttpServletResponse response)  {
		setUserInfoPage(request,response);
		return "/userCenter_myIntegral";
	}
	//财务中心
	@RequestMapping({ "/financeCenter" })
	public String financeCenter(HttpServletRequest request, HttpServletResponse response)  {
 			TycoinUser tycoinUser=setUserInfoPageResultUser(request,response);
			if(tycoinUser!=null){
		 		TycoinAccount tycoinAccount =tycoinAccountService.findOneByuserId(String.valueOf(tycoinUser.getId()));
		 		
		 		request.setAttribute("tycoinAccount",tycoinAccount);
	 		}else{
	 			return "/login";
	 		}
			return "/financeCenter";
	}
	
	//充币
	@RequestMapping({ "/financeCenter_chargeIcon" })
	public String financeCenterChargeIcon(HttpServletRequest request, HttpServletResponse response)  {
			setUserInfoPage(request,response);
			String userId = String.valueOf(request.getSession().getAttribute("userId"));
			List <TycoinUserWallet> tycoinUserWalletList  =tycoinUserWalletService.getTycoinUserWalletForUser(userId);
			for (TycoinUserWallet tycoinUserWallet : tycoinUserWalletList) {
				String walletType=tycoinUserWallet.getWalletType();
				if(walletType.equals("LTC")){
					request.setAttribute("ltcAddress", tycoinUserWallet.getAddress());
					request.setAttribute("ltcAddressImg", tycoinUserWallet.getAddressImg());	
				}else if(walletType.equals("BTC")){
					request.setAttribute("btcAddress", tycoinUserWallet.getAddress());	
					request.setAttribute("btcAddressImg", tycoinUserWallet.getAddressImg());	
				}else if(walletType.equals("ETH")){
					request.setAttribute("ethAddress", tycoinUserWallet.getAddress());
					request.setAttribute("ethAddressImg", tycoinUserWallet.getAddressImg());	
				}else if(walletType.equals("ETC")){
					request.setAttribute("etcAddress", tycoinUserWallet.getAddress());	
					request.setAttribute("ethAddressImg", tycoinUserWallet.getAddressImg());	
				}
			}
			return "/financeCenter_chargeIcon";
	}	
	
	//充值
	@RequestMapping({ "/financeCenter_transaction" })
	public String financeCenterTransaction(HttpServletRequest request, HttpServletResponse response)  {
			setUserInfoPage(request,response);
			return "/financeCenter_transaction";
	}	
	//提现
	@RequestMapping({ "/financeCenter_withdrawals" })
	public String financeCenterWithdrawalsl(HttpServletRequest request, HttpServletResponse response)  {
			setUserInfoPage(request,response);
			return "/financeCenter_withdrawals";
	}	
	
	//财务中心
	@RequestMapping({ "/financeCenter_user" })
	public String financeCenterUser(HttpServletRequest request, HttpServletResponse response)  {
 		TycoinUser tycoinUser=setUserInfoPageResultUser(request,response);
 		if(tycoinUser!=null){
	 		TycoinAccount tycoinAccount =tycoinAccountService.findOneByuserId(String.valueOf(tycoinUser.getId()));
	 		request.setAttribute("tycoinAccount",tycoinAccount);
		}
			return "/financeCenter_user";
	}
	
	//绑定银行卡
	@RequestMapping({ "/financeCenter_bindBankCard" })
	public String financeCenterBindCard(HttpServletRequest request, HttpServletResponse response)  {
		    TycoinUser tycoinUser=setUserInfoPageResultUser(request,response);
		if(tycoinUser!=null){
			List<TycoinUserBank> tycoinUserBankList=tycoinUserBankService.findByUserIdAll(String.valueOf(tycoinUser.getId()));
			for (TycoinUserBank tycoinUserBank : tycoinUserBankList) {
				String bankNo=tycoinUserBank.getBankNo();
				tycoinUserBank.setBankNo(bankNo.substring(0,6)+"****"+bankNo.substring(bankNo.length()-3, bankNo.length()));
			}
			  request.setAttribute("tycoinUserBankList", tycoinUserBankList);
 		}
 			
			return "/financeCenter_bindBankCard";
	}	
	//我的历史账单
	@RequestMapping({ "/financeCenter_historyBill" })
	public String financeCenterBinHistoryBill(HttpServletRequest request, HttpServletResponse response)  {
			setUserInfoPage(request,response);
			return "/financeCenter_historyBill";
	}	
	
	//新闻咨询详情页面
	@RequestMapping({ "/news_details_{id}" })
	public String newsDetails(HttpServletRequest request, HttpServletResponse response,@PathVariable("id") Long id)  {
		
		    TycoinUser tycoinUser=setUserInfoPageResultUser(request,response);
			TycoinNews  tycoinNews=tycoinNewsService.findById(id);
			String content=tycoinNews.getContent();
			content=content.replaceAll("\r\n\r\n", "<br/>");
 			tycoinNews.setContent(content);
			request.setAttribute("tycoinNews",tycoinNews);

		if(tycoinUser!=null){
	 		TycoinAccount tycoinAccount =tycoinAccountService.findOneByuserId(String.valueOf(tycoinUser.getId()));
	 		request.setAttribute("tycoinAccount",tycoinAccount);
 		} 
		
		
		return "/news_details";
 	}
	//新闻咨询页面
	@RequestMapping({ "/news" })
	public String news(HttpServletRequest request, HttpServletResponse response)  {
		TycoinUser tycoinUser=setUserInfoPageResultUser(request,response);
		if(tycoinUser!=null){
	 		TycoinAccount tycoinAccount =tycoinAccountService.findOneByuserId(String.valueOf(tycoinUser.getId()));
	 		request.setAttribute("tycoinAccount",tycoinAccount);
 		} 
		return "/news";
 	}
	
	//用户中心
		@RequestMapping({ "/userCenter" })
		public String userCenter(HttpServletRequest request, HttpServletResponse response)  {
	 		boolean bool=setUserInfoPage(request,response);
              if(!bool){
      			return "/login";
              }
  			TycoinUser tycoinUser=setUserInfoPageResultUser(request,response);
       		if(tycoinUser!=null){
    	 		TycoinAccount tycoinAccount =tycoinAccountService.findOneByuserId(String.valueOf(tycoinUser.getId()));
    	 		request.setAttribute("tycoinAccount",tycoinAccount);
     		}
			return "/userCenter";
	 	}
	
		
		//用户中心——用户
		@RequestMapping({ "/userCenter_user" })
		public String userCenterUser(HttpServletRequest request, HttpServletResponse response)  {
			TycoinUser tycoinUser=setUserInfoPageResultUser(request,response);
			if(tycoinUser!=null){
				TycoinUserLoginLog tycoinUserLoginLog =tycoinUserLoginLogService.findByUserIdLast(tycoinUser.getId());
		 		 request.setAttribute("tycoinUserLoginLog",tycoinUserLoginLog);
			}
 			return "/userCenter_user";
	 	}
		
		//用户中心——实名
		@RequestMapping({ "/userCenter_realname" })
		public String userCenterRealname(HttpServletRequest request, HttpServletResponse response)  {
	 		 setUserInfoPage(request,response);
			return "/userCenter_realname";
	 	}
	
		
		
 
 
	
	
	@RequestMapping( value = "getVerify/codeimg", produces = "application/json;charset=UTF-8", method = RequestMethod.POST)
	@ResponseBody
	public String img( HttpServletRequest request, HttpServletResponse response) throws IOException  {
		String result="";
	    //生成随机字串 
        String verifyCode = VerifyCodeUtils.generateVerifyCode(4); 
        //存入会话session 
        HttpSession session = request.getSession(true); 
        //删除以前的
        session.removeAttribute("verCode");
        session.setAttribute("verCode", verifyCode.toLowerCase()); 
        //生成图片 
        int w = 100, h = 30; 
        
        String	file=SpringContextHolder.getRootRealPath() + "\\static\\verifyCode+"+verifyCode+"_"+new java.util.Random().nextInt(100)+".png";

        VerifyCodeUtils.outoputImg2(w, h, file,verifyCode);
        
        Map<String ,String> map  =new HashMap<String,String>();
        map.put("filePath", file);
        map.put("verifyCode", verifyCode);
        
  		return result;
	}
	
	//获取K线
	@RequestMapping( value = "/getkLine", produces = "application/json;charset=UTF-8")
	@ResponseBody
	public String getkLine( HttpServletRequest request, HttpServletResponse response) throws IOException  {
		HttpClientUtils hc=new HttpClientUtils();
		String kurl=request.getParameter("kurl");
		String cointype=request.getParameter("cointype");
        String result= hc.get(kurl);  
        if("eth".equals(cointype)||"etc".equals(cointype)){
             net.sf.json.JSONObject json=net.sf.json.JSONObject.fromObject(result);
             if(result.indexOf("data")!=-1){
                result=json.getString("data");
            }
        }

      	return result;
	}

	
	
	
	
	
	public boolean setUserInfoPage(HttpServletRequest request, HttpServletResponse response){
		boolean falg=false;
		String userId = String.valueOf(request.getSession().getAttribute("userId"));
		TycoinUser tycoinUser = null;
		if(StringUtil.isNotNull(userId)){
			tycoinUser = this.tycoinUserService.findById(Long.valueOf(userId));
		}
		if(tycoinUser!=null){
 			request.setAttribute("tycoinUser", tycoinUser);
			request.setAttribute("userId", userId);
	 	    String hiddenIDCard=tycoinUser.getIdcard();  //身份证
	 	    if(hiddenIDCard !=null){
	 	       int  cardLength=hiddenIDCard.length();
	 	       hiddenIDCard=hiddenIDCard.substring(0,4)+"****"+hiddenIDCard.substring(cardLength-2,cardLength);
		 	   request.setAttribute("hiddenIDCard", hiddenIDCard);
	 	    }
	 	   String mobileHidden=tycoinUser.getMobile();  //手机号
		    if(mobileHidden !=null){
		 	       int  mobileLength=mobileHidden.length();
		 	      mobileHidden=mobileHidden.substring(0,3)+"****"+mobileHidden.substring(mobileLength-4,mobileLength);
			 	   request.setAttribute("mobileHidden", mobileHidden);
		 	    }
		 	String hiddenEmail=tycoinUser.getEmail();  //邮箱
			    if(hiddenEmail !=null){
			 	       int  EmailLength=hiddenEmail.length();
			 	      hiddenEmail=hiddenEmail.substring(0,2)+"****"+hiddenEmail.substring(EmailLength-9,EmailLength);
				 	   request.setAttribute("hiddenEmail", hiddenEmail);
			 	    }
			falg=true;
   		}
		return falg;

	}
	
	
	public TycoinUser setUserInfoPageResultUser(HttpServletRequest request, HttpServletResponse response){
 		String userId = String.valueOf(request.getSession().getAttribute("userId"));
		TycoinUser tycoinUser = null;
		if(StringUtil.isNotNull(userId)){
			tycoinUser = this.tycoinUserService.findById(Long.valueOf(userId));
		}
		if(tycoinUser!=null){
 			request.setAttribute("tycoinUser", tycoinUser);
			request.setAttribute("userId", userId);
	 	    String hiddenIDCard=tycoinUser.getIdcard();  //身份证
	 	    if(hiddenIDCard !=null){
	 	       int  cardLength=hiddenIDCard.length();
	 	       hiddenIDCard=hiddenIDCard.substring(0,5)+"****"+hiddenIDCard.substring(cardLength-4,cardLength);
		 	   request.setAttribute("hiddenIDCard", hiddenIDCard);
	 	    }
	 	   String mobileHidden=tycoinUser.getMobile();  //手机号
		    if(mobileHidden !=null){
		 	       int  mobileLength=mobileHidden.length();
		 	      mobileHidden=mobileHidden.substring(0,3)+"****"+mobileHidden.substring(mobileLength-4,mobileLength);
			 	   request.setAttribute("mobileHidden", mobileHidden);
		 	    }
		 	String hiddenEmail=tycoinUser.getEmail();  //邮箱
			    if(hiddenEmail !=null){
			 	       int  EmailLength=hiddenEmail.length();
			 	      hiddenEmail=hiddenEmail.substring(0,2)+"****"+hiddenEmail.substring(EmailLength-9,EmailLength);
				 	   request.setAttribute("hiddenEmail", hiddenEmail);
			 	    }
			
			return tycoinUser;
    		}
         return null;
	}

	/********
	 * 完善更新用户资料
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping({ "/updateUserInfo" })
	@ResponseBody
	public BaseRespose  updateUserInfo(HttpServletRequest request, TycoinUser tycoinUser,HttpServletResponse response)  {
		TycoinUser user=tycoinUserService.findById((Long) request.getSession().getAttribute("userId"));
		user.setCountry(request.getParameter("country"));
		user.setCard_type(request.getParameter("card_type"));
		user.setRealname(request.getParameter("realname"));
		user.setIdcard(request.getParameter("usernumber"));
		user.setSex(Integer.parseInt(request.getParameter("sex")));
		user.setJob(request.getParameter("job"));
		user.setAddress(request.getParameter("address"));
		user.setIsRealname(1);//如果需要人工审核，注视掉这行
		tycoinUser.setSecurityLevel(tycoinUser.getSecurityLevel()+1);
 		this.tycoinUserService.save(user);
		baseRespose.setMassage("成功");
		baseRespose.setCode(200);
		return baseRespose;
	}

	/*********
	 * 上传身份证
	 * @param file
	 * @param request
	 * @param memberCode
	 * @return
	 * @throws IOException
	 */
	@RequestMapping("/uploadIdCard")
	@ResponseBody
	public  BaseRespose uploadIdCard(@RequestParam(value="imgFile",required=false) MultipartFile[] file, HttpServletRequest request, HttpServletResponse response,String memberCode) throws IOException {
		response.setCharacterEncoding("UTF-8"); 
		response.setContentType("text/json");
		response.setHeader("Access-Control-Allow-Origin","*");
		TycoinUserRealnamePic userRealnamePic=new TycoinUserRealnamePic();
		if(file == null||file.length<3){
			baseRespose.setMassage("请上传三张图片");
			baseRespose.setCode(4001);
			return baseRespose;
		}
		String userId = String.valueOf(request.getSession().getAttribute("userId"));
		String wechat=request.getParameter("wechat");
		if(userId==null||userId.equals("null")||userId.equals("")){
			if (wechat!=null&&wechat.length()>1){
				TycoinUser tycoinUser=tycoinUserService.findOneByweixin(wechat);
				if (tycoinUser!=null)
					userId=tycoinUser.getId()+"";
			}
		}
		if(userId==null||userId.equals("null")||userId.equals("")){
			baseRespose.setMassage("请登陆");
			baseRespose.setCode(4002);
			return baseRespose;
			
		}
		for (MultipartFile multipartFile : file) {
			if (multipartFile.getSize()<1024*500)
			{
				baseRespose.setMassage("图片大小不能小于200k");
				baseRespose.setCode(4001);
				return baseRespose;
			}
		}
		String idCardFront=saveImg(file[0],userId,userRealnamePic,0);
		String idCardback=saveImg(file[1],userId,userRealnamePic,1);
		String idCardhand=saveImg(file[2],userId,userRealnamePic,2);
		if (!IdCardidentifyFront(userRealnamePic,userId,idCardFront)){
			baseRespose.setMassage("身份证正面识别失败");
			baseRespose.setCode(4006);
			return baseRespose;
		}
		if (!IdCardidentifyBack(userRealnamePic,userId,idCardback)){
			baseRespose.setMassage("身份证反面识别失败");
			baseRespose.setCode(4007);
			return baseRespose;
		}
		this.tycoinUserRealnamePicService.save(userRealnamePic);
		baseRespose.setCode(200);
		baseRespose.setData(userRealnamePic);
 		System.out.println("姓名为："+userRealnamePic.getName());
		return  baseRespose;
	}


	/********
	 * 识别身份证正面
	 * @param userRealnamePic
	 * @param userId
	 * @param imgPath
	 * @return
	 */
	private boolean IdCardidentifyFront(TycoinUserRealnamePic userRealnamePic
			,String userId,String imgPath){
		JSONObject jsonObject= Verification.VerificationIdCardOcr(imgPath,0);
		System.out.println(jsonObject.toString());
		userRealnamePic.setUserId(Integer.valueOf(userId));
		try {
			if (jsonObject.getString("name")!=null)
				userRealnamePic.setName(jsonObject.getString("name"));
		} catch (JSONException e) {
			return false;
		}
		try {
			if (jsonObject.getString("sex")!=null)
				userRealnamePic.setSex(jsonObject.getString("sex"));
		} catch (JSONException e) {
			return false;
		}
		try {
			if (jsonObject.getString("birth")!=null)
				userRealnamePic.setBirth(jsonObject.getString("birth"));
		} catch (JSONException e) {
			return false;
		}
		try {
			if (jsonObject.getString("id")!=null)
				userRealnamePic.setIdcard(jsonObject.getString("id"));
		} catch (JSONException e) {
			return false;
		}
		try {
			if (jsonObject.getString("address")!=null)
				userRealnamePic.setAddress(jsonObject.getString("address"));
		} catch (JSONException e) {
			return false;
		}
		return true;
	}

	/*********
	 * 识别身份证反面
	 * @param userRealnamePic
	 * @param userId
	 * @param imgPath
	 * @return
	 */
	private boolean IdCardidentifyBack(TycoinUserRealnamePic userRealnamePic
			,String userId,String imgPath){
		JSONObject jsonObject= Verification.VerificationIdCardOcr(imgPath,1);
		userRealnamePic.setUserId(Integer.valueOf(userId));
		try {
			if (jsonObject.getString("authority")!=null)
				userRealnamePic.setAuthority(jsonObject.getString("authority"));
		} catch (JSONException e) {
			return false;
		}
		try {
			if (jsonObject.getString("valid_date")!=null)
				userRealnamePic.setValid_date(jsonObject.getString("valid_date"));
		} catch (JSONException e) {
			return false;
		}
		return true;
	}



	/*****
	 * 保存用户上传身份证
	 * @param multipartFile
	 * @param usetId
	 * @param tycoinUserRealnamePic
	 * @param type
	 * @return
	 * @throws IOException
	 */
	private String saveImg(MultipartFile multipartFile,String usetId
			,TycoinUserRealnamePic tycoinUserRealnamePic,int type) throws IOException {
//		String filePath = "D:/WorkProjects/ProjectsJava/tycoin/tycoinApp/src/main/webapp/static/IDCardImg/";
		String filePath=String.format(SpringContextHolder.getRootRealPath()+"\\static\\IDCardImg\\user_"+usetId+"\\idcard%d",type);
		String fileName = multipartFile.getOriginalFilename();
		File file2 = new File(filePath+usetId, fileName);
   		 File dir = file2.getParentFile();
	        if(!dir.exists()){
	            dir.mkdirs();
	        }

		if(!file2.exists()){
			file2.createNewFile();
		}
		multipartFile.transferTo(file2);
		switch (type)
		{
			case 0:
				tycoinUserRealnamePic.setCardPic1(file2.getAbsolutePath());
				break;
			case 1:
				tycoinUserRealnamePic.setCardPic2(file2.getAbsolutePath());
				break;
			case 2:
				tycoinUserRealnamePic.setCardPic3(file2.getAbsolutePath());
				break;
		}
		tycoinUserRealnamePic.setUserId(Integer.valueOf(usetId));
		return file2.getAbsolutePath();
	}

	

/**
 * 退出
 * */
	@RequestMapping(value = "/exitUser" , method = RequestMethod.GET)
	public String exit(HttpServletRequest request, HttpServletResponse response) {
		request.getSession().removeAttribute("userName");
		request.getSession().removeAttribute("passWord");
		request.getSession().removeAttribute("userId");
		Cookie cookie = new Cookie("userInfo", null);
		cookie.setMaxAge(0);
		cookie.setPath("/");
		response.addCookie(cookie);
		return "/index";
	}
	
	
	
	@RequestMapping(value = "/findAllProvince", produces = "application/json;charset=UTF-8")
	@ResponseBody
	public Map<String, Object> findAllProvince(HttpServletRequest request,HttpServletResponse response) {
		Map<String,Object>  map=new HashMap<String,Object>();
	    List<TycoinSysArea> list=tycoinSysAreaService.findAllProvince();
		map.put("provinceList", list);
 		return map;
  	}
	
	
	
	@RequestMapping(value = "/findCityBycode", produces = "application/json;charset=UTF-8")
	@ResponseBody
	public Map<String, Object> findCityBycode(HttpServletRequest request,HttpServletResponse response) {
		Map<String,Object>  map=new HashMap<String,Object>();
		String areaCode=request.getParameter("areaCode");
	    List<TycoinSysArea> list=tycoinSysAreaService.findCityBycode(areaCode);
		map.put("cityList", list);
 		return map;
  	}

	
	@RequestMapping(value = "/findAreaBycode", produces = "application/json;charset=UTF-8")
	@ResponseBody
	public Map<String, Object> findAreaBycode(HttpServletRequest request,HttpServletResponse response) {
		Map<String,Object>  map=new HashMap<String,Object>();
		String areaCode=request.getParameter("areaCode");
	    List<TycoinSysArea> list=tycoinSysAreaService.findAreaBycode(areaCode);
		map.put("areaList", list);
 		return map;
  	}

	
	/********
	 * 完善更新用户资料
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value= "/savaAddBank", produces = "application/json;charset=UTF-8")
	@ResponseBody
	public Map<String,String>  savaAddBank(HttpServletRequest request, HttpServletResponse response)  {
          Map<String,String> map=new HashMap<String,String>();
  	    TycoinUser tycoinUser=setUserInfoPageResultUser(request,response);
  		String mobilephone = request.getParameter("mobilephone");
  		String bankCode= request.getParameter("bankCode");
  		String bankName= request.getParameter("bankName");
   		String bankCardCode= request.getParameter("bankCardCode");
  		String areaCode= request.getParameter("areaCode");
   		
  		 TycoinUserBank  tycoinUserBank=new TycoinUserBank();
   		tycoinUserBank.setUserId(tycoinUser.getId()+"");
   		tycoinUserBank.setArea(areaCode);
   		tycoinUserBank.setBankName(bankName);
   		tycoinUserBank.setBankCode(bankCode);
    	tycoinUserBank.setBankMobile(mobilephone);
   		tycoinUserBank.setBankNo(bankCardCode);
   		tycoinUserBankService.save(tycoinUserBank);
  		map.put("code", "200");
          
		return map;
	}
	
	@RequestMapping(value= "/deleteBank" , produces = "application/json;charset=UTF-8")
	@ResponseBody
	public Map<String,String>  deleteBank(HttpServletRequest request, HttpServletResponse response)  {
          Map<String,String> map=new HashMap<String,String>();
   		String bankid = request.getParameter("bankid");
   		TycoinUserBank tycoinUserBank=tycoinUserBankService.findById(Long.valueOf(bankid));
   		tycoinUserBankService.delete(tycoinUserBank);
  		map.put("code", "200");
          
		return map;
	}
	
	
	
	//买入挂单
	@RequestMapping(value= "/buyTradeOrder/buy" , produces = "application/json;charset=UTF-8")
	@ResponseBody
	public Map<String,String>  buyTradeOrder(HttpServletRequest request, HttpServletResponse response)  {
          Map<String,String> map=new HashMap<String,String>();
          String userId = String.valueOf(request.getSession().getAttribute("userId"));

          TycoinUser tycoinUser=setUserInfoPageResultUser(request,response);
           
          String coinType=request.getParameter("coinType");
          String buyMoney=request.getParameter("buyMoney");//买入价格
          String buyNum=request.getParameter("buyNum");//个数
          String nowPrice=request.getParameter("nowPrice");//当前价格
          String sumMoney=request.getParameter("sumMoney");//总金额
          String planType=request.getParameter("planType");//计划
           TycoinTradeOrder tycoinTradeOrder=new TycoinTradeOrder();
          tycoinTradeOrder.setUserId(userId);
          tycoinTradeOrder.setCoinType(coinType);
          tycoinTradeOrder.setMoney(new BigDecimal(buyMoney));
          tycoinTradeOrder.setType(1);//买
          tycoinTradeOrder.setNum(new BigDecimal(buyNum));
          tycoinTradeOrder.setPaymentTime(new Date());
          tycoinTradeOrder.setStatus(0);
          tycoinTradeOrder.setPlanType(Integer.valueOf(planType));
          tycoinTradeOrder.setSumMoney(new BigDecimal(sumMoney));
          tycoinTradeOrderService.save(tycoinTradeOrder);
          //挂单成功
          //冻结账户资金
          TycoinAccount tycoinAccount=tycoinAccountService.findOneByuserId(userId);
          tycoinAccount.setUseMoney(tycoinAccount.getUseMoney().subtract(new BigDecimal(sumMoney)));
          tycoinAccount.setNoMoney(tycoinAccount.getNoMoney().add(new BigDecimal(sumMoney)));
           tycoinAccountService.save(tycoinAccount);
          
              map.put("code", "200");
             map.put("msg", "挂单成功");
          
		return map;
	}
	
	//卖出挂单
	@RequestMapping(value= "/sellTradeOrder/sell" , produces = "application/json;charset=UTF-8")
	@ResponseBody
	public Map<String,String>  sellTradeOrder(HttpServletRequest request, HttpServletResponse response)  {
          Map<String,String> map=new HashMap<String,String>();
   		String userId = String.valueOf(request.getSession().getAttribute("userId"));

          TycoinUser tycoinUser=setUserInfoPageResultUser(request,response);
           
          String coinType=request.getParameter("coinType");
          String sellMoney=request.getParameter("sellMoney");
          String sellNum=request.getParameter("sellNum");
          String buyPrice=request.getParameter("buyPrice");
          String sumMoney=request.getParameter("sumMoney");
          String planType=request.getParameter("planType");//计划
          TycoinTradeOrder tycoinTradeOrder=new TycoinTradeOrder();
          tycoinTradeOrder.setUserId(userId);
          tycoinTradeOrder.setCoinType(coinType);
          tycoinTradeOrder.setMoney(new BigDecimal(sellMoney));
          tycoinTradeOrder.setType(2);//卖
          tycoinTradeOrder.setNum(new BigDecimal(sellNum));
          tycoinTradeOrder.setPaymentTime(new Date());
          tycoinTradeOrder.setSumMoney(new BigDecimal(sumMoney));
          tycoinTradeOrder.setStatus(0);
          tycoinTradeOrder.setPlanType(Integer.valueOf(planType));
          tycoinTradeOrderService.save(tycoinTradeOrder);
          //挂单成功
          //冻结币
          TycoinAccount tycoinAccount=tycoinAccountService.findOneByuserId(userId);
           if("BTC".equals(coinType)){
        	  tycoinAccount.setUseBtc(tycoinAccount.getUseBtc().subtract(new BigDecimal(sellNum)));
        	  tycoinAccount.setNoBtc(tycoinAccount.getNoBtc().add(new BigDecimal(sellNum)));
           } if("LTC".equals(coinType)){
        	  tycoinAccount.setUseLtc(tycoinAccount.getUseLtc().subtract(new BigDecimal(sellNum)));
        	  tycoinAccount.setNoLtc(tycoinAccount.getNoLtc().add(new BigDecimal(sellNum)));
          } if("ETH".equals(coinType)){
        	  tycoinAccount.setUseEth(tycoinAccount.getUseEth().subtract(new BigDecimal(sellNum)));
        	  tycoinAccount.setNoEth(tycoinAccount.getNoEth().add(new BigDecimal(sellNum)));
          } if("ETC".equals(coinType)){
        	  tycoinAccount.setUseEtc(tycoinAccount.getUseEtc().subtract(new BigDecimal(sellNum)));
        	  tycoinAccount.setNoEtc(tycoinAccount.getNoEtc().add(new BigDecimal(sellNum)));
          }
          tycoinAccountService.save(tycoinAccount);
          
              map.put("code", "200");
             map.put("msg", "挂单成功");
          
		return map;
	}
	
	
	
	//创建BTC账户
	@RequestMapping(value= "/createWallet/btc" , produces = "application/json;charset=UTF-8")
	@ResponseBody
	public Map<String,String>  createWalletBTC(HttpServletRequest request, HttpServletResponse response) throws Exception  {
		//创建比特币莱特币账户
        Map<String, String> map = new HashMap<String, String>();
        TycoinUser tycoinUser=setUserInfoPageResultUser(request,response);
        if(tycoinUser.getIsEmail()!=1){
        	map.put("code", "205");
        	map.put("message", "请先实名邮箱");
	        return map;
        }
       //创建比特币莱特币账户
		Map<String, String> params = new HashMap<> ();
    	HttpClientUtils hc=new HttpClientUtils();
    	params.put("password", tycoinUser.getPassword());
    	String apiCode=VerifyCodeUtils.generateVerifyCode(32);
    	params.put("api_code",  apiCode);
    	String priv=VerifyCodeUtils.generateVerifyCode2(35);
    	//先用固定值
    	///params.put("priv ", "1K7GZRDkSNFsjy1czhMRz3MVGLjecNbeYr");
    	params.put("lable ", tycoinUser.getId()+"");
    	
    	params.put("email", tycoinUser.getEmail());
     	
	        String Result=hc.post("http://localhost:3000/api/v2/create", params);
			        net.sf.json.JSONObject json= net.sf.json.JSONObject.fromObject(Result);
 
 		        	String address=json.getString("address");
		        	String guid=json.getString("guid");
			        	TycoinUserWallet tycoinUserWallet=new TycoinUserWallet();
		        	tycoinUserWallet.setUserId(tycoinUser.getId()+"");
			        	tycoinUserWallet.setAddress(address);
			        	tycoinUserWallet.setApiCode(apiCode);
		        	tycoinUserWallet.setGuid(guid);
		        	tycoinUserWallet.setWalletType("BTC");
		        	
		          	//创建二维码图片
		        	String erweima="/static/addressImg/"+tycoinUser.getId()+"btcaddress_"+address+".png";
		        	MatrixToImageWriter.erweiMa(address, SpringContextHolder.getRootRealPath()+erweima);
		        	tycoinUserWallet.setAddressImg(erweima);
		        	tycoinUserWalletService.save(tycoinUserWallet);
		        	System.out.println("创建BTC账户成功！--------");
		     
		        

		        map.put("code", "200");
		        map.put("message", "创建BTC成功");

		        return map;
	}
	
	
	    //创建LTC账户
		@RequestMapping(value= "/createWallet/ltc" , produces = "application/json;charset=UTF-8")
		@ResponseBody
		public Map<String,String>  createWalletLTC(HttpServletRequest request, HttpServletResponse response) throws Exception  {
			//创建比特币莱特币账户
	        Map<String, String> map = new HashMap<String, String>();
	        TycoinUser tycoinUser=setUserInfoPageResultUser(request,response);
	        if(tycoinUser.getIsEmail()!=1){
	        	map.put("code", "205");
	        	map.put("message", "请先实名邮箱");
		        return map;
	        }
	       //创建比特币莱特币账户
			Map<String, String> params = new HashMap<> ();
	    	HttpClientUtils hc=new HttpClientUtils();
	    	params.put("password", tycoinUser.getPassword());
	    	String apiCode=VerifyCodeUtils.generateVerifyCode(32);
	    	params.put("api_code",  apiCode);
	    	String priv=VerifyCodeUtils.generateVerifyCode2(35);
	    	//先用固定值
	    	///params.put("priv ", "1K7GZRDkSNFsjy1czhMRz3MVGLjecNbeYr");
	    	params.put("lable ", tycoinUser.getId()+"");
	    	
	    	params.put("email", tycoinUser.getEmail());
	     	
		        String Result=hc.post("http://localhost:3000/api/v2/create", params);
		        
				    net.sf.json.JSONObject json= net.sf.json.JSONObject.fromObject(Result);
			        String success=json.getString("success");
			        if("true".equals(success)){
			        	net.sf.json.JSONObject wallet=json.getJSONObject("wallet");
			        	String address=wallet.getString("address");
			        	String guid=wallet.getString("guid");
				        	TycoinUserWallet tycoinUserWallet=new TycoinUserWallet();
			        	tycoinUserWallet.setUserId(tycoinUser.getId()+"");
				        tycoinUserWallet.setAddress(address);
				        tycoinUserWallet.setApiCode(apiCode);
			        	tycoinUserWallet.setGuid(guid);
			        	tycoinUserWallet.setWalletType("BTC");
			        	
			        	//创建二维码图片
			        	String erweima="/static/addressImg/"+tycoinUser.getId()+"btcaddress_"+address+".png";
			        	MatrixToImageWriter.erweiMa(address, SpringContextHolder.getRootRealPath()+erweima);
			        	tycoinUserWallet.setAddressImg(erweima);
			        	tycoinUserWalletService.save(tycoinUserWallet);
			        	System.out.println("创建BTC账户成功！--------");
			        }
			        map.put("200", "创建BTC成功");
			        return map;
		}
		
	
	    //创建LTC账户
		@RequestMapping(value= "/uploadTest" , produces = "application/json;charset=UTF-8")
		@ResponseBody
		public String  uploadTest(HttpServletRequest request, HttpServletResponse response) throws Exception  {
			
		//长传ftp
	     String text = "http://www.baidu.com?aaa=1&bbb=2"; // 二维码内容
	        int width = 300; // 二维码图片宽度
	        int height = 300; // 二维码图片高度
	        String format = "jpg";// 二维码的图片格式

	        Hashtable<EncodeHintType, String> hints = new Hashtable<EncodeHintType, String>();
	        hints.put(EncodeHintType.CHARACTER_SET, "utf-8"); // 内容所使用字符集编码

	        BitMatrix bitMatrix = new MultiFormatWriter().encode(text,
	                BarcodeFormat.QR_CODE, width, height, hints);
	        // 生成二维码
	        String filePath="D:/javaTools/Tomcat7.0/webapps/ftp/ftpIMG/news_"+RandomUtils.getRandomString(6)+".jpg";
  	        File outputFile = new File(filePath);
 	     
	        MatrixToImageWriter.writeToFile(bitMatrix, format, outputFile);
 	        
	        return   filePath;
		}

	
 
}
